package com.itheima.wemedia.mq;

import com.alibaba.fastjson.JSON;
import com.itheima.wemedia.service.WmNewsService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class WmNewsVerifyListener {

    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 监听风控结果
     * @param record
     */
    @KafkaListener(topics = "wmnews_save_queue",groupId = "wmnewssavegroup")
    public void verifyResult(ConsumerRecord<String,Object> record){
        String result = record.value().toString();

        Map<String,Object> map = JSON.parseObject(result, Map.class);

        wmNewsService.autoVerify(map);
    }
}
